<template>
	<view>
		<view class="flex flex-direction bg-white padding-xl justify-between ">	
			<view class="flex flex-direction" v-for="(item,index) in orderItems" :key="index" style="margin-bottom: 20upx;">
				<!-- 订单编号 -->
				<view>订单编号：<text class="text-gray">{{orderInfo.orderSn}}</text></view>
				<view class="flex" style="margin-top: 20upx;">
					<!-- 左部 -->
					<view>
						<image :src="item.skuPic" style="width:150upx;height:150upx;border-radius:10%"/>
					</view>
					<!-- 右部 -->
					<view style="margin-left: 20upx;" class="flex flex-direction justify-around">
						<view>{{item.skuName}}</view>
						<view class="text-gray">支付金额:<text>{{orderInfo.totalAmount}}</text></view>
						<view class="text-gray">数量:<text>{{item.skuQuantity}}</text></view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 评价主体部分 -->
		<view class="bg-white" style="margin-top:20upx;border-top: #E6E6E6 solid 1upx;">
			<view style="padding: 20upx;">
				<textarea maxlength="-1" class="line-black" v-model="commentText" placeholder="请输入评论"></textarea>
			</view>
			<text style="" class="text-gray text-center margin-left">——————多写点好评就有机会被精选———————</text>
		</view>
		
		<!-- 下部分评论 -->
		<view class="bg-white padding-xl">
			<view class="flex align-center"><text class="margin-right">快递包装</text><uni-rate v-model="value2"/></view>
      
			<view class="flex align-center"><text class="margin-right">快递速度</text><uni-rate v-model="value3"/></view>
    
			<view class="flex align-center"><text>配送员服务</text><uni-rate v-model="value4"/></view>
		</view>
		
		<view @tap="postComment" class="cu-btn bg-red round" style="width: 710upx;height: 100upx;margin-top: 20upx; margin-left: 20upx;margin-right: 20upx;">发表评论</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value2:2,
				value3:3,
				value4:4,
				//-------
				memberId:undefined,
				orderId:undefined,
				skuId:undefined,
				commentText:'',
				orderInfo:{},
				orderItems:[]
			}
		},
		onLoad(options) {
			this.memberId = options.memberId
			this.orderId = options.orderId
			console.log('options',options)
			this.getOrderInfo()
		},
		methods: {
			onChange(e) {
				console.log('onChange',e.value)
			},
			async getOrderInfo(){
				var res = await this.$request({
					url:`cartorder/order/orderItemList/${this.orderId}`,
					params:{},
					type:"GET"
				})
				if(res.code == 0){
					this.orderInfo = res.order 
					this.orderItems = res.items
				}
			},
			postComment() {
				this.orderItems.forEach(item=>{
					this.changeStatus(item.orderId)
					if(!this.sendComment(item.skuId)){
						uni.showToast({
							title:'评价失败！',
							icon:'none'
						})
						return
					}
				})
				uni.showToast({
					title:'评价成功！',
					icon:'none'
				})
				uni.redirectTo({
					url:'../order/orderCRM?type=3'
				})
			},
			
			async sendComment(skuId) {
				var res = await this.$request({
					baseURL:`http://192.168.42.101:88/`,
					url:'cartorder/comment/addComment',
					params:{
						memberId:Number(this.memberId),
						orderId:Number(this.orderId),
						skuId:Number(skuId),
						commentText:this.commentText
					},
					type:"POST"
				})
				if(res.msg == '评价成功'){
					return true
				}
				return false			
			},
			
			async changeStatus(orderId){
				var res = await this.$request({
					baseURL:'http://192.168.42.101:88/',
					url:`cartorder/order/orderStatus/${orderId}/${2}`,
					params:{},
					type:'GET'
				})
			}
		},
	}
</script>

<style>

</style>
